/**
 * @file:          Pid.h
 * @brief:
 * @details:
 * @author:        wjh
 * @date created:  2023.06.14
 * @version:       1.0.0
 * @par copyright (c):
 *
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.06.14,00:47:52
 */

#ifndef _PID_H_
#define _PID_H_

/* Include Files **************************************************************/
#include "Datatype.h"

/* Macro Definition ***********************************************************/

/* Data Type Define ***********************************************************/
enum PID_MODE
{
    PID_MODE_KP_KI_COUPLING = 0,
    PID_MODE_KP_KI_INDEPENDENT = 1,
};
typedef struct Pid
{
    /* public data */
    enum PID_MODE param_pid_mode;
    // Filter_FirstOrder ud_filter;
    // FalLinear fal;
    uint16 param_en;
    uint16 param_bypass;
    float32 param_T;
    float32 param_kp;
    float32 param_ki;
    float32 param_kd;
    float32 param_kc; /* anti-windup gain */
    float32 param_limit_ref;
    float32 param_limit_ui;
    float32 parma_limit_out;
    float32 in_ref;
    float32 in_fdb;
    float32 out;
    float32 err;
    float32 last_err;
    float32 kp;
    float32 ki;
    float32 kd;
    float32 up;
    float32 ui;
    float32 ui_last;
    float32 out_presat;
    float32 ui_anti_windup_trim;
    float32 ud;

    /* private data */

    /* public method */
    uint8 (*Init)(struct Pid *self);
    float32 (*Run)(struct Pid *self);
    void (*Clear)(struct Pid *self);

    /* private method */

} Pid;

/* Variable Declare ***********************************************************/

/* Function Declare ***********************************************************/
uint8 Pid_Init(struct Pid *self);
float32 Pid_Run(struct Pid *self);
void Pid_Clear(struct Pid *self);

#endif